package com.yunji.hushuang;

import java.util.Arrays;

import static com.yunji.hushuang.CloneUtil.deepClone;

/**
 * @author hushuang
 * @since 2019/10/12
 */
public class CloneTest {


    private static void testDeepClone(Person person) {
        System.out.println("-------------------------------");

        Person copy = deepClone(person);
        System.out.println(person);
        System.out.println(copy);

        System.out.println(person.getName());
        System.out.println(copy.getName());
        System.out.println(person.getName() == copy.getName());

        System.out.println(person.getHobbies());
        System.out.println(copy.getHobbies());
        System.out.println(person.getHobbies() == copy.getHobbies());
    }

    private static void testShallowClone(Person person) {
        System.out.println("-------------------------------");

        Person clone = person.clone();
        System.out.println(person);
        System.out.println(clone);

        System.out.println(person.getName());
        System.out.println(clone.getName());
        System.out.println(person.getName() == clone.getName());

        System.out.println(person.getHobbies());
        System.out.println(clone.getHobbies());
        System.out.println(person.getHobbies() == clone.getHobbies());
    }

    public static void main(String[] args) {
        Person person = new Person();
        person.setName("张三");
        person.setHobbies(Arrays.asList("学习", "游泳"));

        testShallowClone(person);
        testDeepClone(person);
    }
}
